package com.itheima;

import java.awt.*;

public class Bullet {
    private int x, y;
    private final int width = 5;
    private final int height = 15;

    public Bullet(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public int getX() {
        return x;
    }

    public int getY() {
        return y;
    }

    public void moveUp() {
        y -= 7;
    }

    public void draw(Graphics g) {
        // 绘制子弹
        g.setColor(Color.WHITE);
        g.fillRect(x, y, width, height);
    }

    public boolean collidesWith(Monster monster) {
        return x < monster.getX() + monster.getWidth() &&
                x + width > monster.getX() &&
                y < monster.getY() + monster.getHeight() &&
                y + height > monster.getY();
    }
}
